package com.tgpms.web.element.controller;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tgpms.common.Result;
import com.tgpms.exception.ExceptionExplain;
import com.tgpms.exception.QueryException;
import com.tgpms.util.Common;
import com.tgpms.web.element.service.SubCheckService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author newway
 * <p>
 * 物资审核相关接口
 */
@Api(value = "SubCheckController", tags = "物资管理 物资审核相关接口")
@RestController
@RequestMapping(value = "/ev/subCheck")
public class SubCheckController {

	private final Logger log = LoggerFactory.getLogger(this.getClass());
	
	@Resource 
	private SubCheckService subCheckService;
	
	@ApiOperation(value = "查询合同集合接口", notes = "查询合同集合接口", httpMethod = "POST")
	@PostMapping(value = "/getPoList")
	public Result getPoList(@RequestParam(value = "dataowner", required = false) String dataowner) {
		log.info("查询合同集合接口接收到的值为："+dataowner);
		Result result = new Result();
		if(Common.isEmpty(dataowner)) {
			result.setSuccess(false);
			result.setMsg(ExceptionExplain.EMPTY_BY_DATA.getExplain());
			return result;
		}
		try {
			result = subCheckService.getPoList(result,dataowner);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg(ExceptionExplain.ERROR_BY_QUERY.getExplain());
			throw new QueryException(ExceptionExplain.ERROR_BY_QUERY.getExplain());
		}
		return result;
	}
	
	@ApiOperation(value = "查询合同物资设备树形接口", notes = "查询合同物资设备树形接口", httpMethod = "POST")
	@PostMapping(value = "/getPoSubTreeList")
	public Result getPoSubTreeList(
			@RequestParam(value = "poNo", required = false)String poNo,
			@RequestParam(value = "name", required = false)String name,
			@RequestParam(value = "dataowner", required = false) String dataowner) {
		log.info("查询合同物资设备树形接口接收到的值为："+poNo,name,dataowner);
		Result result = new Result();
		if(Common.isEmpty(poNo) || Common.isEmpty(dataowner)) {
			result.setSuccess(false);
			result.setMsg(ExceptionExplain.EMPTY_BY_DATA.getExplain());
			return result;
		}
		try {
			result = subCheckService.getPoSubTreeList(result,poNo,name,dataowner);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg(ExceptionExplain.ERROR_BY_QUERY.getExplain());
			throw new QueryException(ExceptionExplain.ERROR_BY_QUERY.getExplain());
		}
		return result;
	}
	
}
